<template>
  <div v-show="isReady" class="live-flex-content">
    <div class="live-flex-header">
      <live-header-bar />
    </div>
    <div class="live-flex-body">
      <div class="live-content">
        <live-content />
      </div>
      <div class="chat-user-side"></div>
    </div>
    <!-- 不支持 webrtc -->
    <not-web-rtc v-if="!supportWebRtc" />
  </div>
</template>

<script>
import { mapState } from "vuex";
import liveDeviceUtils from "@/utils/live-device.js";
import RtcDetection from "@/utils/rtc-detection.js";
import LiveContent from "./components/live-content/index";
import LiveHeaderBar from "./components/live-header-bar/index";
import NotWebRtc from "./components/not-webrtc/index";
// import RtcClient from "@/utils/rtc-client";

export default {
  name: "Live",
  components: { LiveContent, LiveHeaderBar, NotWebRtc },
  data() {
    return {
      isReady: false,
      rtcClient: null,
      supportWebRtc: true,
      liveDeviceUtils: liveDeviceUtils
    };
  },
  provide() {
    return {
      live: this
    };
  },
  computed: {
    ...mapState("live", ["roomInfo", "userSign"])
  },
  methods: {
    async getDevice() {
      await this.liveDeviceUtils.init();
    }
  },
  async created() {
    //需要先检测相关设备在开始实例化client
    //需要创建 RtcClient shareClient
    // let { SDKAppId: sdkAppId, userSig } = this.userSign;
    // let { userId, roomId } = this.roomInfo;
    // this.rtcClient = new RtcClient({
    //   sdkAppId,
    //   userSig,
    //   userId,
    //   roomId
    // });
    const rtcDetectioin = new RtcDetection();
    this.supportWebRtc = await rtcDetectioin.rtcDetection();
    this.isReady = true;
    if (this.supportWebRtc) {
      await this.liveDeviceUtils.init();
    }

    console.log(this.liveDeviceUtils.cameraList);
  }
};
</script>

<style lang="scss">
.live {
  &-flex-content {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    // .live-content {
    //   flex: 1;
    //   background: orange;
    // }
    // .chat-user-side {
    //   width: 300px;
    //   overflow: hidden;
    // }
  }
  &-flex-header {
    width: 100%;
    height: 60px;
  }
  &-flex-body {
    flex: 1;
  }
}
</style>
